Documentation

TaskController extends AbstractController
in package

Table of Contents

Methods

anonymousTasksAction()  : Response
We create an action to affect all tasks without author to the anonymous user.
createAction()  : Response
Creates a new task.
deleteTaskAction()  : Response
Deletes a task.
doneTasksAction()  : Response
Retrieves and displays the list of completed tasks.
editTaskAction()  : Response
Edit a task.
listAction()  : Response
Retrieves and displays a list of tasks.
toggleTaskAction()  : Response
Toggle the status of a task.
userTasksAction()  : Response
Retrieves and displays the tasks of a specific user.

Methods

anonymousTasksAction()

We create an action to affect all tasks without author to the anonymous user.

public anonymousTasksAction(EntityManagerInterface $emi) : Response
Parameters
$emi : EntityManagerInterface
Return values
Response

createAction()

Creates a new task.

public createAction(EntityManagerInterface $emi, Request $request) : Response

This method is responsible for creating a new task. It checks if the user is authenticated, and if not, it redirects them to the login page. It creates a new instance of the Task entity and a form to handle the task creation. If the form is submitted and valid, the task is persisted to the database and a success flash message is displayed. Finally, the user is redirected to the task list page.

Parameters
$emi : EntityManagerInterface

The entity manager interface.

$request : Request

The request object.

Return values
Response

The response object.

deleteTaskAction()

Deletes a task.

public deleteTaskAction(Task $task, EntityManagerInterface $emi) : Response

This method is responsible for deleting a task from the database. It checks if the user is authenticated and has the necessary permissions to delete the task. If the user is not authenticated, they are redirected to the login page with a flash message indicating that they need to be logged in to delete a task. If the user is not the author of the task and does not have the ROLE_ADMIN role, they are redirected to the task list page with a flash message indicating that they cannot delete a task that does not belong to them. If the user is authenticated and has the necessary permissions, the task is removed from the database and a success flash message is displayed. Finally, the user is redirected to the task list page.

Parameters
$task : Task

The task to be deleted.

$emi : EntityManagerInterface

The entity manager interface used to interact with the database.

Return values
Response

The response object.

doneTasksAction()

Retrieves and displays the list of completed tasks.

public doneTasksAction(EntityManagerInterface $emi) : Response
Parameters
$emi : EntityManagerInterface

The entity manager interface.

Return values
Response

The response object.

editTaskAction()

Edit a task.

public editTaskAction(Task $task, EntityManagerInterface $emi, Request $request) : Response

This method allows the user to edit a task. If the user is not logged in, they will be redirected to the login page. If the user is not the author of the task and does not have the ROLE_ADMIN role, they will be redirected to the task list page. If the form is submitted and valid, the task will be updated and the user will be redirected to the task list page.

Parameters
$task : Task

The task to be edited.

$emi : EntityManagerInterface

The entity manager interface.

$request : Request

The request object.

Return values
Response

The response object.

listAction()

Retrieves and displays a list of tasks.

public listAction(EntityManagerInterface $emi) : Response
Parameters
$emi : EntityManagerInterface

The entity manager interface.

Return values
Response

The response object.

toggleTaskAction()

Toggle the status of a task.

public toggleTaskAction(Task $task, EntityManagerInterface $emi) : Response

This method toggles the status of a task between "done" and "not done". If the user is not logged in, they will be redirected to the login page. After toggling the status, a success flash message is added and the user is redirected to the task list page.

Parameters
$task : Task

The task to toggle.

$emi : EntityManagerInterface

The entity manager interface.

Return values
Response

The response object.

userTasksAction()

Retrieves and displays the tasks of a specific user.

public userTasksAction(User $user, EntityManagerInterface $emi) : Response
Parameters
$user : User

The user whose tasks are to be displayed.

$emi : EntityManagerInterface

The entity manager interface.

Return values
Response

The response object.


        
On this page

Search results